﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

namespace NGE
{
    internal class Mouse
    {
        public Mouse(Game g)
        {
            game = g;
        }

        Game game;
        bool mslb, msrb;
        int x, y;
        public void Heartbeat()
        {
            //for (int j = 0; j < MsgQue.Count; j++)
            {
                Message msg = game.SysMsg.msg;

                x = msg.LParam.ToInt32() & 0xffff;
                y = (msg.LParam.ToInt32() >> 16) & 0xffff;
                if (msg.Msg == 0x200)
                {
                    for (int i = 0; i < game.Components.Count; i++)
                    {
                        game.Components[i].NotifyMouseEvent(x, y, MouseState.Move);
                    }
                }
                else if (msg.Msg == 0x201)
                {
                    for (int i = 0; i < game.Components.Count; i++)
                    {
                        if (mslb == false)
                        {
                            game.Components[i].NotifyMouseEvent(x, y, MouseState.LButtonDown);
                            mslb = true;
                        }
                        else
                        {
                            game.Components[i].NotifyMouseEvent(x, y, MouseState.LButtonHold);
                        }
                    }
                }
                else if (msg.Msg == 0x202)
                {
                    for (int i = 0; i < game.Components.Count; i++)
                    {
                        game.Components[i].NotifyMouseEvent(x, y, MouseState.LButtonUp);
                        mslb = false;
                    }
                }
                else if (msg.Msg == 0x204)
                {
                    for (int i = 0; i < game.Components.Count; i++)
                    {
                        if (msrb == false)
                        {
                            game.Components[i].NotifyMouseEvent(x, y, MouseState.RButtonDown);
                            msrb = true;
                        }
                        else
                        {
                            game.Components[i].NotifyMouseEvent(x, y, MouseState.RButtonHold);
                        }
                    }
                }
                else if (msg.Msg == 0x205)
                {
                    for (int i = 0; i < game.Components.Count; i++)
                    {
                        game.Components[i].NotifyMouseEvent(x, y, MouseState.RButtonUp);
                        msrb = false;
                    }
                }
            }
        }
        //Queue<Message> MsgQue = new Queue<Message>();

        //public void Push(Message msg)
        //{
        //    if (msg.Msg >= 0x200 && msg.Msg < 0x210)
        //    {
        //        MsgQue.Enqueue(msg);
        //    }
        //}
    }
}
